﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sustainalytics.LongRunningTaskManager.Interface;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Sustainalytics.LongRunningTaskManager.Tests
{
    [TestClass]
    public class LongRunningTaskResultFactoryTests
    {
        private static List<Type> _taskResultTypes;
        private ILongRunningTaskResultFactory _resultTypeFactory;

        [ClassInitialize]
        public static void ClassInitialize(TestContext testContext)
        {
            _taskResultTypes = new List<Type>
            {
                typeof(LongRunningTaskObjectResult),
                typeof(LongRunningTaskFileInMemResult),
                typeof(LongRunningTaskFileOnDiskResult)
            };
        }

        [TestInitialize]
        public void TestInitialize()
        {
            _resultTypeFactory = new LongRunningTaskResultFactory();
        }


        [TestMethod]
        public void GetTaskResultTypes()
        {
            var expectedValue = _taskResultTypes;

            var value = _resultTypeFactory.GetTaskResultTypes();

            Assert.IsNotNull(value, "Returned value is null.");
            Assert.IsTrue(expectedValue.All(er => value.Any(vr => vr == er)), "Not all result types were returned.");
        }

        [TestMethod]
        public void GetTaskResultType_Object()
        {
            Type expectedValue = typeof(LongRunningTaskObjectResult);

            Type value = _resultTypeFactory.GetTaskResultType(LongRunningTaskResultTypeEnum.Object);

            Assert.IsNotNull(value, "Returned value is null.");
            Assert.IsTrue(value == expectedValue, "Returned value is different than expected value.");
        }

        [TestMethod]
        public void GetTaskResultType_FileInMem()
        {
            Type expectedValue = typeof(LongRunningTaskFileInMemResult);

            Type value = _resultTypeFactory.GetTaskResultType(LongRunningTaskResultTypeEnum.FileInMem);

            Assert.IsNotNull(value, "Returned value is null.");
            Assert.IsTrue(value == expectedValue, "Returned value is different than expected value.");
        }

        [TestMethod]
        public void GetTaskResultType_FileOnDisk()
        {
            Type expectedValue = typeof(LongRunningTaskFileOnDiskResult);

            Type value = _resultTypeFactory.GetTaskResultType(LongRunningTaskResultTypeEnum.FileOnDisk);

            Assert.IsNotNull(value, "Returned value is null.");
            Assert.IsTrue(value == expectedValue, "Returned value is different than expected value.");
        }
    }
}
